<template>
  <div class="product-content">
       <Top title="我的足迹"  iconShow='1'></Top>
       <!-- 这个是 顶部的切换栏-->
       <div class="tab">
          <ul>
              <li>
                <a href="javascript:void(0)" class="select">
                      产品
                      <div class="showborder"></div>
                </a>  
              </li>
              <li><a href="./mydiscoverZiXun.html">资讯</a></li>
              <li><a href="./mydiscoverTieZi.html">帖子</a></li>
          </ul>
       </div>
       <!-- 这个是编辑 -->
      <div class="product-content-edit" @click="goEdit">{{edit?"取消":"编辑"}}</div>
       <!-- 注意这里是加下拉组件的 -->
    <div class="productList-content" v-for="(item,index) in dataList" :key="index">
      <div v-if="edit" class="tiezi-content-item-check">
            <input type="checkbox" :id="item.visitId" class="chk_1" ref="checkbox" @change="singleSelect" :cId="item.visitId" />
            <label :for="item.visitId"></label>               
      </div>
      <div class="productList-content-logo">
            <div class="productList-content-logo-img" @click="goDetail(item.platformId)">
                <img :src="item.logo" alt="产品">
            </div>
      </div>
      <div class="productList-content-detail">
        <div class="productList-content-detail-top clearfix">
          <div class="productList-content-detail-top-left">
            <p>{{item.abbreviation}}</p>
            <div class="clearfix">
              <ul class="clearfix">
                 <li v-for="(itemC,idx) in item.label.split(',')" :key="idx">{{itemC}}</li>
              </ul>
            </div>
          </div>
          <div class="productList-content-detail-top-right">
            <mt-button type="primary" @click="  goDetail(item.platformId)">
              立即申请
            </mt-button>
          </div>
        </div>
        <div class="productList-content-detail-mid">
         <span>¥</span>
          <span>{{item.quato}}</span>
          <span>额度范围&nbsp;(元)</span>
        </div>
        <div class="productList-content-detail-bot">
          <ul>
            <li>{{item.lendSpeed}}放款</li>
            <li>参考日费率:{{item.dailyInterestRate}}%</li>
            <li>贷款期限{{item.maxCycle}}</li>
          </ul>
        </div>
      </div>
    </div>
    <!-- 顶部的固定删除功能 -->
    <div class="deleteDo" v-if="edit">
      <div class="deleteDo-left">
        <label for="checkAll">
          <input type="checkbox" id="checkbox_a1" class="chk_1 checkall" ref="allSelect" @change="allSelect"/>
          <label for="checkbox_a1"></label>
        </label>
        <span style="position:absolute;">全选</span>
        <span>{{selectNum}}/{{ dataList.length}}</span>
      </div>
      <div class="deleteDo-right" @click="shanchu">删除</div>
    </div>
    <!-- 如果一个产品没有，那么空的图片则显示 -->
    <div class="showing" v-if="dataList.length==0">
          <img src="../../../assets/nothing.png" alt="">
    </div>
    <loading title="加载中..."  v-if="loadMoreShow"></loading>
    <Nomore v-if="noMoreShow"></Nomore>
  </div>
</template>

<script>
import Vue from 'vue'
import '../../../js/lib/flexble.js'
import commons from '../../../common/js/common.js'
import Top from 'components/Header/Header'
import Foot from 'components/Footer/Footer'
import { Indicator, MessageBox,Toast } from "mint-ui";
export default {
  name: 'collectProduct',
  components: { Top,Foot },
  data() {
    return {
            pageNum: 1,
            edit: false,
            selectNum: 0,
             dataList: [],
              selectNum: 0,
              noMoreShow:false,
               flag: true,
                arr: [],
                idStr: '',
                loadMoreShow: false,
                dedaultImg:{userimg:'../static/img/user.png'} //表示的是用来处理默认图片的
    }
  },
  created() {
        var _this = this;
        this.$nextTick(function() {
          window.addEventListener('scroll', onScroll)
        })
        // 判断滚动条位置，加载更多
        function onScroll() {
          var scrollTop = document.body.scrollTop;
          var innerHeight = window.innerHeight;
          var offsetHeight = document.body.offsetHeight;
          if (scrollTop + innerHeight >= offsetHeight) {
            if (_this.flag) {
              if (_this.dataList.length >= 6) {
                //console.log(1111)
                _this.flag = false;
                _this.getList()
              }
            }
          }
        }
  },
  mounted(){ 
    Vue.http.interceptors.push((request, next) => { //请求拦截器
      //请求前
      request.headers.set('token', commons.getCookie('token')); //设置请求头
      Indicator.open('加载中...'); //请求loading
      next((response) => {
        //请求后
        Indicator.close(); //隐藏loading
        return response
      })
    })
      var _this = this;
      var token = commons.getCookie("token");
      // 获取访问的资讯列表
      this.$http.get("/loansupermarket-app/foot/getCustomInformationVisit?pageNum=" + _this.pageNum + "&&pageSize=6" + '&visitType=' + 3 + "&token=" + token)
        .then((response) => {
          _this.loadMoreShow = false;
          var resBody = response.data;
          if (resBody.code == '000') {
            _this.dataList = resBody.data;
            // 如果最后一页列表的长度小于6，说明已经没有更多了
            if (_this.dataList.length < 6) {
              _this.noMoreShow = true;
               _this.flag=false; 
            }
            // 时间戳转成2018-10-08格式
            _this.dataList.forEach(function(item, index) {
              if(item.logo==null||item.logo==""){ //注意这里用来判断是否后台传进来的为空，然后显示默认的图片
                      item.logo=_this.dedaultImg.userimg;
              }
            })
          } else if (resBody.code == '444') {
            window.location.href="../user/login.html?history=1";
          }else{
            MessageBox.alert(resBody.mesg);
          }
        })
    },
    methods: {
      goDetail(id) {  //进入相关的页面
        var token =commons.getCookie("token");
         window.location.href='../loan/product.html?id='+id+'&status=2';
        //注意这个请求是为后面的我的足迹中的产品添加记录
        this.$http.post('/loansupermarket-app/foot/insertInformationVisit',{token:token,visitType:3,informationId:id}).then(()=>{
        });
      },
      // 分页加载
    getList() {
      this.pageNum += 1;
      this.loadMoreShow = true;
      var token =commons.getCookie("token");
      var _this = this;
      setTimeout(function() {
        _this.$http.get("/loansupermarket-app/foot/getCustomInformationVisit?pageNum=" + _this.pageNum + "&&pageSize=6" + '&visitType=' + 3 + "&token=" + token)
          .then((response) => {
            _this.loadMoreShow = false;
            var resBody = response.body;
            if (resBody.code == '000') {
              if (_this.edit) {
                if (resBody.data.length == 0) {
                  _this.$refs.allSelect.checked = true;
                } else {
                  _this.$refs.allSelect.checked = false;
                }
              }
              if (resBody.data.length < 6) {
                _this.noMoreShow = true;
                _this.flag = false;
              } else {
                _this.flag = true;
              }
              _this.dataList = _this.dataList.concat(resBody.data);
              _this.dataList.forEach(function(item, index) {
                  if(item.logo==null||item.logo==""){ //注意这里用来判断是否后台传进来的为空，然后显示默认的图片
                      item.logo=_this.dedaultImg.userimg;
                  }
              })
            }else if(resBody.code=='444'){
              window.location.href="../user/login.html?history=1";
            }else{
              MessageBox.alert(resBody.mesg);
            }
          })
      }, 500)
    },
        // 编辑功能
        goEdit() {
            this.edit = !this.edit;
            if (!this.edit) {
                this.selectNum = 0;
            }
        },
        //选择复选款的功能
        singleSelect() {
            var _this = this;
            var flag = true;
            //var checkboxs=document.querySelectorAll('.ss');
          this.$refs.checkbox.forEach(function(item, index) {
              if (!item.checked) {
                _this.$refs.allSelect.checked = false;
                flag = false;
                return false;
              }
              if (flag) {
                _this.$refs.allSelect.checked = true;
              }
            })
            // 判断已选列表个数
            this.judgeNum();
        },
         // 判断已选列表个数
        judgeNum() {
          var _this = this;
          _this.selectNum = 0;
          this.$refs.checkbox.forEach(function(item, index) {
            if (item.checked) {
              _this.selectNum += 1
            }
          })
        },
         // 如果是全选，那么所有的checkbox全部变成已选
        allSelect() {
          var _this = this;
          if (this.$refs.allSelect.checked) {
            this.$refs.checkbox.forEach(function(item, index) {
              item.checked = true;
            })
          } else {
            this.$refs.checkbox.forEach(function(item, index) {
              item.checked = false;
            })
          }
          // 判断已选列表个数
          this.judgeNum();
        },
        shanchu() {  //删除
            var _this = this;
            var token = commons.getCookie("token");
            this.$refs.checkbox.forEach(function(item, index) {
                if (item.checked) {
                    _this.arr.push(item.getAttribute('cId'));
                    _this.idStr = _this.arr.join(',');
                }
            })

            if (this.idStr.length == 0) {
                Toast('请勾选你要删除的帖子~');
            } else {
                this.$http.post('/loansupermarket-app/foot/deleteInformationVisit', { visitType: 3, idStr: this.idStr, token: token }).then(function(response) {
                    if (response.body.code == '000') {
                        Toast('删除成功！');
                        setTimeout(function() {
                            window.location.reload()
                        }, 500)
                    } else if (response.body.code == '444') {
                        window.location.href="../user/login.html?history=1";
                    } else {
                        MessageBox.alert(response.body.mesg);
                    }
                })
            }
        },
    }
}
</script>
<style lang="scss" scoped>
@import '../../../scss/base.scss';
//这个是tab栏的样式
.tab{
  border-bottom: 1px solid #e4e4e4;
      margin-top: 1.2rem;
      position: fixed!important;
      width: 100%;
      top: 0;
      background: #fff;
      z-index: 3;
      height: 1.2rem;
      line-height: 1.2rem;
      display: flex;
    >ul{
      display:flex;
       width: 100%;
      height: 100%;
      box-sizing: border-box;
      li{   
        font-size:14px;
        font-weight: bold;
        position:relative; 
          flex:1;
          text-align:center;
          &:after{
            content:'';
            position:absolute;
            width:1px;
            height:rem(50);
            background: #e4e4e4;
            right:0px;
            top:50%;
            margin-top:rem(-25);
          }
          a{
            display: block;
            color: #666;
          }
           .select{
                 color: rgb(48, 204, 219);
             }
      }
      .showborder{
        position:absolute;
        width:rem(150);
        height:1px;
        background:rgb(48, 204, 219);
        bottom:-1px;
        left:50%;
        margin-left:rem(-75);
      }
      
    }
}
.showing{
  margin-top: rem(120);
}
  .product-content {
    text-align: center;
      overflow: hidden;
        margin-top: 2.7rem;
        width: 100%;
        box-sizing: border-box;
        &-edit {
            position: fixed;
            right: 0.4rem;
            top: 0.35rem;
            z-index: 999;
            color: #fff;
            font-size: 0.4rem;
        }
    }
 .productList{
   &-content {
   background: #fff;
    width: 100%;
    // height: 3.44rem;
     padding: 0rem 0.4rem;
    margin-bottom: 0.27rem;
    background: #fff;
    box-sizing: border-box;
    display: flex;
    &-logo {
      margin:0 0.2rem;
      flex: 2;
      padding: 0.3rem 0;
      &-img {
        width: 1.2rem;
        height: 1.2rem;
        border-radius: 50%;
        margin: 0.4rem auto;
        overflow: hidden;
        img {
          width: 100%;
          height: 100%;
        }
      }
    }

    &-detail {
      flex: 8;
      background: #fff;
      padding: 0.3rem 0;
      &-top {
        // height: 1.54rem;
          display: flex;
        &-left {
          float: left;
          text-align: left;
          width: 5.5rem;
          p {
            text-align: left;
            margin-top: 0.38rem;
            height: 0.4rem;
            font-size: 0.42rem;
          }
          ul {
            margin-top: 0.32rem;
            li {
              float: left;
              width: 1.32rem;
              height: 0.45rem;
              border: 1px solid $grayColor;
              text-align: center;
              line-height: 0.45rem;
              border-radius: 0.12rem;
              margin-right: 0.13rem;
              color: $grayColor;
              margin-top: 0.1rem;
              font-size: 12px;
            }
          }
        }
        &-right {
          float: left;
          width: 2.3rem;
           margin-right: 0.2rem;
          .mint-button {
            padding: 0px 12px;
            margin-top: 0.4rem;
            font-size: 0.36rem;
            height: 0.9rem;
          }
        }
      }
      &-mid {
        height: 0.4rem;
        margin-top: 0.3rem;
        text-align: left;
        span:nth-of-type(1) {
          color: $redColor;
          font-size: 0.42rem;
        }
        span:nth-of-type(2) {
          color: $redColor;
          font-size: 0.5rem;
          margin-left: 0.1rem;
        }
        span:nth-of-type(3) {
          color: $grayColor;
          font-size: 0.3rem;
          margin-left: 0.25rem;
        }
      }
      &-bot {
        ul {
          padding: 0.35rem 0;
          li {
            float: left;
            padding: 0 0.2rem;
            font-size: 0.3rem;
            &:nth-of-type(1) {
              padding-left: 0;
            }
            &:nth-of-type(2) {
              border-left: 1px solid $borderColor;
              border-right: 1px solid $borderColor;
            }
          }
        }
      }
    }
  }
}
.tiezi-content-item-check{
      input {
        margin-top: 1rem;
        width: 0.4rem;
        height: 0.4rem;
      }

}
//这个是切除浮动的代码
.clearfix::after,
.clearfix::before {
	content: ".";
	line-height: 0;
	height: 0;
	display: block;
	visibility: hidden;
	clear: both;
}
.clearfix {
	*zoom: 1;
}
//这个是复选款的样式
.chk_1{
   display: none; // vertical-align: -15%;
    width: 0.3rem;
    height: 0.3rem;
}
.chk_1+label {
    color:#fff !important;
    margin-top: 1.1rem;
    background-color: #FFF;
    border: 1px solid #C1CACA;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05),
    inset 0px -15px 10px -12px rgba(0, 0, 0, 0.05);
    padding: 0.2rem;
    border-radius: 50%;
    display: inline-block;
    position: relative;
    width: 0.1rem;
    height: 0.1rem; 
    //margin-left: 0.3rem;
    margin-right: 0.2rem;
  }
  .chk_1+label:active {
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05), inset 0px 1px 3px rgba(0, 0, 0, 0.1);
  }
  .chk_1:checked+label {
    font-size: 0.17rem;
    margin-top: 1.1rem;
    background-color: $primaryColor;
    border: 1px solid $primaryColor;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05), inset 0px -15px 10px -12px rgba(0, 0, 0, 0.05), inset 15px 10px -12px rgba(255, 255, 255, 0.1);
    color: #243441;
  }
  .chk_1:checked+label:after {
    content: '\2714'; //勾选符号 
    position: absolute;
    top: 0px;
    left: 0px;
    color: #fff;
    width: 100%;
    text-align: center;
    font-size: 1.4em; // padding: 1px 0 0 0;
    vertical-align: text-top;
  }
//这个是顶部删除的样式
.deleteDo {
  z-index:1000;
    display: flex;
    width: 100%;
    position: fixed;
    left: 0;
    height: 1.3rem; // line-height: 1.3rem;
    color: #fff;
    bottom: 0;
    &-left {
      flex: 6;
      background: rgba(0, 0, 0, 0.4);
      border-right: 1px solid #fff;
      text-align: left;
      box-sizing: border-box;
      
      padding: 0 0.4rem;
      .chk_1+label {
        margin-top: 0.35rem;
        background-color: #FFF;
        border: 1px solid #C1CACA;
        box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05), inset 0px -15px 10px -12px rgba(0, 0, 0, 0.05);
        padding: 0.2rem;
        border-radius: 50%;
        display: inline-block;
        position: relative;
        margin-right: 30px; // display: none;
        // vertical-align: -15%;
        width: 0.1rem;
        height: 0.1rem;
      }
      .chk_1:checked+label {
        margin-top: 0.35rem;
        background-color: $primaryColor;
        border: 1px solid $primaryColor;
        box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05), inset 0px -15px 10px -12px rgba(0, 0, 0, 0.05), inset 15px 10px -12px rgba(255, 255, 255, 0.1);
        color: #243441;
      }

      span {
        float: right;
        line-height: 1.3rem;
        font-size: 0.3rem;
      }
    }
    &-right {
      font-size: 0.3rem;
      flex: 3;
      line-height: 1.3rem;
      background: rgba(0, 0, 0, 0.4)
    }
  }
</style>
